import Vue from 'vue'

////console.log(Vue.prototype);
//角色管理等级过滤
Vue.filter('roleStageCode',function(value){
  let newValue = "";
  if( value[1] === "stageCode" ){
    switch (value[0][value[1]]){
      case "1":
        newValue = "市局";
        break;
      case "2":
        newValue = "分局";
        break;
      case "3":
        newValue = "派出所/警务站";
        break;
      default:
        newValue = "";
        break;
    }
  }else if ( value[1] === "createTime" ){
    let oldTime = value[0][value[1]];
    newValue = oldTime.split("T")[0] + " " + oldTime.split("T")[1].split(".")[0];
  }else{
    newValue = value[0][value[1]];
  }
  ////console.log(value);
  return newValue;
});

// 通用的fliter
Vue.filter('subName',function(_json){
  let value = "";
  let tdJson = _json[0];
  let key = _json[1];
  ////console.log(key);
  if( key.indexOf("|") != -1 ){
    let tdArr = key.split("|");
    ////console.log(tdArr);
    value =  tdJson[tdArr[0]][tdArr[1]];
  }else{
    value = tdJson[key];
  }
  return value;
});

//是否在线
Vue.filter('isOnline',function(_json){
  let value = "";
  let tdJson = _json[0];
  let key = _json[1];
  if( key === "isonline" ){
    if( tdJson[key] === 1 ){
      value = "在线"
    }else{
      value = "离线"
    }
  }else{
    value = tdJson[key];
  }
  return value;
});

//是否禁用
Vue.filter('isDisable',function(code){
  //console.log(code);
  //console.log(typeof code);
  let value = "";
  if( code === 1 ){
    value = "启用"
  }else{
    value = "禁用"
  }
  //console.log(value);
  return value;
});

//是否为领导
Vue.filter('isDisable',function(code){
  //console.log(code);
  //console.log(typeof code);
  let value = "";
  if( code === 1 ){
    value = "启用"
  }else{
    value = "禁用"
  }
  //console.log(value);
  return value;
});

//时间
Vue.filter('TimeFilter',function(value){
  let str = "";
  if( value[1] === "createTime" ){
    str = value[0][value[1]].split("T")[0];
  }else{
    str = value[0][value[1]];
  }
  return str
});

//重点人列表过滤
Vue.filter('keyPersonListFilter',function(value){
  ////console.log(value);
  let newValue = "";
  let _Json = value[0];
  let _JsonKey = value[1];

  if( _JsonKey.indexOf("|") > 0 ){
    let arrKey = _JsonKey.split("|");
    if( arrKey.length === 2 ){
      if( _Json[arrKey[0]] ){
        if( arrKey[1] === "birthday" ){
          if( _Json[arrKey[0]][arrKey[1]] ){
            let strArr = _Json[arrKey[0]][arrKey[1]].split("T");
            newValue = strArr[0];
          }
        }else if( arrKey[1] === "personLevel" ){
          ////console.log(_Json[arrKey[0]][arrKey[1]]);
          switch (_Json[arrKey[0]][arrKey[1]]){
            case "1":
              newValue = "一级";
              break;
            case "2":
              newValue = "二级";
              break;
            case "3":
              newValue = "三级";
              break;
          }
        }

      }
    }else{
      let arrKey = _JsonKey.split("|");
      if( _Json[arrKey[0]].length > 0 ){
        newValue =  _Json[arrKey[0]][0][arrKey[1]][arrKey[2]]
      }

    }

  }else{
    newValue = _Json[_JsonKey];
  }

  return newValue;
});

//预案步骤过滤
Vue.filter('caseTypeFilter',function(val){
  let value = "";
  ////console.log(val);
  if( val[1] === "type" ){
    switch (val[0][val[1]]) {
      case "default":
        value = "默认";
        break;
      case "mustdo":
        value = "必做";
        break;
      case "tips":
        value = "提示";
        break;
    }
  }else{
    value = val[0][val[1]]
  }
  return value;
});

//预案列表
Vue.filter('caseResourceFilter',function(val){
  let value  = "";

  if( val[1] === "emergencyFacilityModelList" ){
    let arr = val[0][val[1]];
    let arrStr = "";
    if( arr.length > 0 ){
      for( let i=0;i<arr.length;i++ ){
        if( arr[i] ){
          arrStr += arr[i].name + "；"
        }
      }
      value = arrStr;
    }
  } else if( val[1] === "createTime" ){
    ////console.log(Vue.prototype.isLogin());
    value = Vue.prototype.JPtool.timestampChangeDate(val[0][val[1]])
  } else{
    value = val[0][val[1]];
  }
  return value;
});

//根据key匹配value；
/*Vue.filter('caseResourceFilter',function(key,dataList){

});*/



















